package com.cimp.service.c2.client;

/**
 * [简要描述]:
 * [详细描述]:
 *
 * @author huojinhao
 * @date 2019/1/8
 */
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.Remote;
import java.util.HashSet;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import org.apache.axis.AxisFault;
import org.apache.axis.EngineConfiguration;
import org.apache.axis.client.Service;
import org.apache.axis.client.Stub;

public class CSPRequestServiceLocator extends Service implements CSPRequestService {
    private String ctms_address = "http://127.0.0.1";
    private String ctmsWSDDServiceName = "ctms";
    private HashSet ports = null;

    public CSPRequestServiceLocator() {
    }

    public CSPRequestServiceLocator(EngineConfiguration config) {
        super(config);
    }

    public CSPRequestServiceLocator(String wsdlLoc, QName sName) throws ServiceException {
        super(wsdlLoc, sName);
    }

    public void setctmsAddress(String ip, String port) {
        this.ctms_address = "http://" + ip + ":" + port + "/cimp/services/ctms";
    }

    public String getctmsAddress() {
        return this.ctms_address;
    }

    public String getctmsWSDDServiceName() {
        return this.ctmsWSDDServiceName;
    }

    public void setctmsWSDDServiceName(String name) {
        this.ctmsWSDDServiceName = name;
    }

    public CSPRequest getctms() throws ServiceException {
        URL endpoint;
        try {
            endpoint = new URL(this.ctms_address);
        } catch (MalformedURLException var3) {
            throw new ServiceException(var3);
        }

        return this.getctms(endpoint);
    }

    public CSPRequest getctms(URL portAddress) throws ServiceException {
        try {
            CtmsSoapBindingStub _stub = new CtmsSoapBindingStub(portAddress, this);
            _stub.setPortName(this.getctmsWSDDServiceName());
            return _stub;
        } catch (AxisFault var3) {
            return null;
        }
    }

    public void setctmsEndpointAddress(String address) {
        this.ctms_address = address;
    }

    public Remote getPort(Class serviceEndpointInterface) throws ServiceException {
        try {
            if (CSPRequest.class.isAssignableFrom(serviceEndpointInterface)) {
                CtmsSoapBindingStub _stub = new CtmsSoapBindingStub(new URL(this.ctms_address), this);
                _stub.setPortName(this.getctmsWSDDServiceName());
                return _stub;
            }
        } catch (Throwable var3) {
            throw new ServiceException(var3);
        }

        throw new ServiceException("There is no stub implementation for the interface:  " + (serviceEndpointInterface == null ? "null" : serviceEndpointInterface.getName()));
    }

    public Remote getPort(QName portName, Class serviceEndpointInterface) throws ServiceException {
        if (portName == null) {
            return this.getPort(serviceEndpointInterface);
        } else {
            String inputPortName = portName.getLocalPart();
            if ("ctms".equals(inputPortName)) {
                return this.getctms();
            } else {
                Remote _stub = this.getPort(serviceEndpointInterface);
                ((Stub)_stub).setPortName(portName);
                return _stub;
            }
        }
    }

    public QName getServiceName() {
        return new QName("iptv", "CSPRequestService");
    }

    public Iterator getPorts() {
        if (this.ports == null) {
            this.ports = new HashSet();
            this.ports.add(new QName("iptv", "ctms"));
        }

        return this.ports.iterator();
    }

    public void setEndpointAddress(String portName, String address) throws ServiceException {
        if ("ctms".equals(portName)) {
            this.setctmsEndpointAddress(address);
        } else {
            throw new ServiceException(" Cannot set Endpoint Address for Unknown Port" + portName);
        }
    }

    public void setEndpointAddress(QName portName, String address) throws ServiceException {
        this.setEndpointAddress(portName.getLocalPart(), address);
    }
}

